package com.Final.hj;

import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class TaskJesksInfo extends AppCompatActivity {

    private TextView task_write_commit;
    private String  task_commit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.task_jesks_info);
        initView();
    }

    public void initView(){
        task_write_commit = (TextView) findViewById(R.id.task_write_commit);
        task_write_commit.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                showCommitDlg();
            }
        });
    }

    //显示发表评论按钮
    public void showCommitDlg(){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        View view = View.inflate(this, R.layout.task_jesks_commit_write_dlg, null);

        //设置页面
        builder.setView(view);

        final AlertDialog dlg = builder.create();

        Button solvBbtn = (Button) view.findViewById(R.id.task_commit_solve);
        Button rejectBtn = (Button) view.findViewById(R.id.task_commit_reject);
        final EditText task_commit_edit = (EditText) view.findViewById(R.id.task_commit_edit);
        final TextView task_commit_max_num = (TextView) view.findViewById(R.id.task_commit_max_num);


        //确认
        solvBbtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){

                //此时这里要判断字数  同样是判断字数
                //合适了 就 发送请求修改数据
                //否则提示

            }
        });

        //点击取消
        rejectBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                dlg.cancel();
            }
        });

        //监听文本款的输入
        task_commit_edit.addTextChangedListener(new TextWatcher() {
            //输入前
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            //输入中  最大值能66个字
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                task_commit = task_commit_edit.getText().toString().trim();
                task_commit_max_num.setText(String.valueOf(66 - task_commit.length()));
            }

            //输入后
            @Override
            public void afterTextChanged(Editable s) {

            }
        });


        dlg.show();
    }
}
